<?php
/* select from config setting */
$get_config_logo = select(Tblrefcode::tblname, array(Tblrefcode::value), array(Tblrefcode::name => 'logo', Tblrefcode::type => 'global_setting'));
$row_config_logo = mysql_fetch_assoc($get_config_logo);
$get_config_title = select(Tblrefcode::tblname, array(Tblrefcode::value), array(Tblrefcode::name => 'site_title', Tblrefcode::type => 'global_setting'));
$row_config_title = mysql_fetch_assoc($get_config_title);
$show_title = ((!empty($row_config_title)) ? $row_config_title[Tblrefcode::value] : $lang['PAGE_TITLE']);
/* end select from config setting */
$usertype = isset($_SESSION['usertype']) ? $_SESSION['usertype'] : '';
?>
<script>
    $(document).ready(function() {
        $("#location li a").click(function() {
            var id = $(this).attr('data-id');
            var text = $(this).text();
            if (id) {
                $('.province').val(id);
                $('#onselected').html(text);
            }
        });
        $(window).bind("load resize", function() {
			console.log($(window).width());
			if ($(window).width() <= 960) {
				$('#mainmenu .navbar-inner .nav-collapse.collapse').addClass('in').css('height', 'auto');
			} else {
				$('#mainmenu .navbar-inner .nav-collapse.collapse').removeClass('in').css('height', '0');;
			}
        });
    });
</script>
<section id="header">
    <div class="header">
        <div class="container">
            <div class="row-fluid">
                <div class="span3">
                    <div id="logo">
                        <a href="<?php echo base_url; ?>" title="<?php echo $show_title; ?>"><img src="<?php if (!empty($row_config_logo)): ?>
                                                                                                      <?php echo base_url; ?>images/<?php echo $row_config_logo[Tblrefcode::value]; ?>" border="0"/>
                                                                                                  <?php else: ?>
                                <?php echo base_url; ?>images/logo.png" border="0"/>
                            <?php endif; ?>
                        </a>
                    </div>
                </div>
                <div class="span9">
                    <div class="row header-rights">
                        <div class="span8 visible-desktop">
                            <?php
                            $table = Tblprovince::tblprovince;
                            $province = select($table, array(), array(), 'province_name ASC');
                            ?>
                            <form action="<?php echo base_url; ?>product" method="GET" class="form-horizontal search" role="form">
                                <div class="input-append btnsearch">
                                    <input class="span12" id="appendedDropdownButton" type="text"  name="search">
                                    <input id="appendedDropdownButton" type="hidden" name="province" class="province">
                                    <div class="btn-group">
                                        <button class="btn dropdown-toggle locations" data-toggle="dropdown">
                                            <span id="onselected" style="float:left; margin-right: 3px">All locations </span>
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu" id="location">
                                            <?php while ($result_pro = mysql_fetch_array($province)) { ?>
                                                <li><a href="#" data-id="<?php echo $result_pro[Tblprovince::id]; ?>"  data-lat="<?php echo $result_pro[Tblprovince::lat_long]; ?>"><?php echo $result_pro[Tblprovince::name]; ?></a></li>
                                            <?php } ?>
                                        </ul>
                                        <button class="btn btn-success btn_location" type="submit" name="btn_location"><i class="icon-search icon-white"></i></button>
                                    </div>

                                </div>
                            </form>
                        </div>
                        <div class="span4" style="text-align: center">
                            <?php
                            if ($usertype == 1) {
                                $logout = base_url . "admin/?logout";
                            } else {
                                $logout = base_url . "/?do=logout";
                            }

                            if ($usertype == 1) {
                                $link = base_url . "admin";
                            } else {
                                $link = base_url . "login.php";
                            }
                            ?>
                            <?php
                            $folder = '';
                            $userId = isset($_SESSION['acc_id']) ? $_SESSION['acc_id'] : '';
                            $folder = 'account/';
                            ?>
                            <?php if (empty($usertype)) { ?>
                                <a href="<?php echo $link; ?>" class="btn btnlogin"><?php echo $lang['MENU_LOGIN']; ?></a>
                                <a href="<?php echo base_url; ?>create_account.php" class="btn btnregister"><?php echo $lang['MENU_SIGN_UP']; ?></a>
                            <?php } else { ?>
                                <ul class="nav nav-pills user-profile">
                                    <li class="dropdown">
                                        <a class="dropdown-toggle user-login" data-toggle="dropdown" href="#">
                                            <i class="icon-user icon-white"></i> <?php echo $lang['MENU_MYACCOUNT']; ?>
                                            <b class="caret"></b>
                                        </a>
                                        <ul class="dropdown-menu">
                                            <li><a href="<?php echo base_url . $folder; ?>"><?php echo @$_SESSION['fullname']; ?></a></li>
                                            <li><a href="<?php echo base_url . $folder; ?>"><?php echo $lang['UR_PROFILE']; ?></a></li>
                                            <li><a href="<?php echo $logout; ?>"><i class="icon-off"></i> <?php echo $lang['MENU_LOGOUT']; ?></a></li>
                                        </ul>
                                    </li>
                                </ul>
<!--                                <a href="<?php echo $logout; ?>" class="btn"><?php echo $lang['MENU_LOGOUT']; ?></a>-->
                            <?php } ?>

                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</section>
<section id="mainnav">
    <nav id="mainmenu">
        <div class="container navbar">
            <form class="form-search serch_m hidden-desktop" action="<?php echo base_url; ?>product" method="GET" role="form">
                <div class="input-append" style="width: 98%">
                    <input type="text" class="span2 search-query serch_text_m" name="search">
                    <select name="province" class="province_s">
                        <option value="">Locations</option>
                        <?php
                        $table = Tblprovince::tblprovince;
                        $province = select($table, array(), array(), 'province_name ASC');
                        while ($result_pro = mysql_fetch_array($province)) {
                            ?>
                            <option value="<?php echo $result_pro[Tblprovince::id]; ?>" data-id="<?php echo $result_pro[Tblprovince::lat_long]; ?>"><?php echo $result_pro[Tblprovince::name]; ?></option>
                        <?php } ?>
                    </select>
                    <button type="submit" name="btn_location" class="btn serch_b_m">Go</button>
                </div>
            </form>
            <div class="navbar-inner">
                <div class="nav-collapse collapse">
                    <ul class="nav megamenu">
                        <li class="<?php
                        if (geturl() == 'home'):echo 'selected';
                        endif;
                        ?> home visible-desktop"><a href="<?php echo W_ROOT; ?>"><span class="menu-title"><?php echo $lang['MENU_HOME']; ?></span></a></li>
                            <?php
                            $get_current = (!empty($_GET['cat_id']) ? $_GET['cat_id'] : '');
                            foreach (build_menu_home() as $category):
                                ?>
                            <li class="<?php
                            echo $category[Tblcategory::cat_class];
                            if ($get_current == $category['id']):echo ' selected ';
                            endif;
                            ?> <?php
                            if (!empty($category[Tblcategory::cat_image])): echo 'menuimg';
                            endif;
                            ?>"><a href="<?php echo base_url; ?>product/?cat_id=<?php echo $category['id']; ?>"><span class="menu-icon">
                                <?php if (!empty($category[Tblcategory::cat_image])): ?>
                                            <img src="<?php echo base_url; ?>/admin/category/image/<?php echo $category[Tblcategory::cat_image]; ?>" height="25px" class="iconimg"/><?php endif; ?></span><?php echo $category['category_name']; ?></a></li>
                        <?php endforeach; ?>
                    </ul>
                </div>
            </div>
        </div>
    </nav>
</section>

<!-- End Header and Nav -->
<div class="clear"></div>